package com.teadent.servlet;

import com.teadent.bean.Person;
import com.teadent.service.*;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/common.action")
public class CommonServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String action= req.getParameter("action");
        Person person=(Person) req.getSession().getAttribute("session_person");
        String userAccount= person.getUserAccount();
        if(action.equals("index")){
            //跳转首页
            req.setAttribute("mainRight","blank.jsp");
            req.getRequestDispatcher("main.jsp").forward(req,resp);
        }


        else if(action.equals("self")){
                //前往个人信息界面
            UserService us=new UserServiceImpl();
            Person self_person = us.getSelf(userAccount);
            req.setAttribute("session_person",self_person);
            req.setAttribute("mainRight","self.jsp");
            req.getRequestDispatcher("main.jsp").forward(req,resp);
        }
    }
}







